//
//  IDSelectViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/11.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "IDSelectViewController.h"
#import "PersonalInfos/PersonalFirstInfoViewController.h"
#import "CompanyInfos/CompanyFirstInfoViewController.h"
#import "PersonalWorkExperienceViewController.h"
#import "CompanySecondInfoViewController.h"
#import "PersonalEducationInfoViewController.h"
#import "AppDelegate.h"
#import "CompanyInfoViewController.h"

@interface IDSelectViewController ()

@end

@implementation IDSelectViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}
- (void)initUI {
    self.navigationItem.title = @"身份选择";
    
    UILabel *topLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 30*Scale, WIDTH, 30*Scale) text:@"请选择您进入比特聘的身份" textColor:THEMECOLOR_OF_TEXT_9a9a9a font:Font_14];
    topLbl.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:topLbl];
    
    UIImage *topImg = [UIImage imageNamed:@"idselect_top"];
    UIImageView *topImgView = [UIToolsControl initImageViewWithFrame:CGRectMake((WIDTH-topImg.size.width)*0.5, EndY(topLbl)+40*Scale, topImg.size.width, topImg.size.height) imageName:nil];
    topImgView.image = topImg;
    [self.view addSubview:topImgView];
    UIButton *topBtn = [UIToolsControl initButtonWithFrame:CGRectMake(100*Scale, EndY(topImgView)+40*Scale, WIDTH-200*Scale, 50*Scale) imageName:nil target:self action:@selector(topBtnTap) title:@"我要找工作" titleColor:COLOR_OF_WHITE];
    topBtn.titleLabel.font = FontBold(Font_17);
    topBtn.layer.cornerRadius = 25*Scale;
    topBtn.layer.masksToBounds = YES;
    topBtn.backgroundColor = THEMECOLOR_OF_ORANGE;
    [self.view addSubview:topBtn];
    
    UIImage *bottomImg = [UIImage imageNamed:@"idselect_bottom"];
    UIImageView *bottomImgView = [UIToolsControl initImageViewWithFrame:CGRectMake((WIDTH-bottomImg.size.width)*0.5, EndY(topBtn)+80*Scale, bottomImg.size.width, bottomImg.size.height) imageName:nil];
    bottomImgView.image = bottomImg;
    [self.view addSubview:bottomImgView];
    UIButton *bottomBtn = [UIToolsControl initButtonWithFrame:CGRectMake(100*Scale, EndY(bottomImgView)+40*Scale, WIDTH-200*Scale, 50*Scale) imageName:nil target:self action:@selector(bottomBtnTap) title:@"我要招聘人才" titleColor:COLOR_OF_WHITE];
    bottomBtn.titleLabel.font = FontBold(Font_17);
    bottomBtn.layer.cornerRadius = 25*Scale;
    bottomBtn.layer.masksToBounds = YES;
    bottomBtn.backgroundColor = THEMECOLOR_OF_ORANGE;
    [self.view addSubview:bottomBtn];
}
- (void)topBtnTap {
    NSLog(@"topBtnTap");
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:@"2" forKey:@"user_role"];
    [BaseNetManager requestWithMethod:POST path:Change_Role_URL params:dic successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            UD_SetOForK(@"2", isUserRole);
//            NSDictionary *data = responseObject[@"data"];
            [DataToolsControl sharedManager].idType = IDTypeOfWorker;
//            PersonalFirstInfoViewController *PFIVC = [[PersonalFirstInfoViewController alloc] init];
//            [self.navigationController pushViewController:PFIVC animated:YES];
            
            NSDictionary *data = responseObject[@"data"];
            [self pushVC:data];
            
            SVPHUDDismiss;
        } else {
            NSString *str = [NSString stringWithFormat:@"%@", responseObject[@"msg"]];
            SVPHUDError(str);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)bottomBtnTap {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:@"1" forKey:@"user_role"];
    [BaseNetManager requestWithMethod:POST path:Change_Role_URL params:dic successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            UD_SetOForK(@"1", isUserRole);
//            NSDictionary *data = responseObject[@"data"];
            [DataToolsControl sharedManager].idType = IDTypeOfCompany;
//            CompanyFirstInfoViewController *CFIVC = [[CompanyFirstInfoViewController alloc] init];
//            [self.navigationController pushViewController:CFIVC animated:YES];
            
            NSDictionary *data = responseObject[@"data"];
            [self pushVC:data];
            
            SVPHUDDismiss;
        } else {
            NSString *str = [NSString stringWithFormat:@"%@", responseObject[@"msg"]];
            SVPHUDError(str);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)pushVC:(NSDictionary *)data {
    if ([data[@"user_guide"] isEqualToString:@"company_add_job"]) { // 添加工作
        [DataToolsControl getMyBaseInfoForCompany:^(BOOL requestFlag) {
            [SharedApp showViewController:TabBarTypeOfCompany];
            UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
            tabBarController.selectedIndex = 1;
        }];
    } else if ([data[@"user_guide"] isEqualToString:@"company_create"]) { // 招聘者下面没有企业的话就会引导创建
        [SharedApp showViewController:TabBarTypeOfSignin];
        
        RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        CompanyFirstInfoViewController *IDSVC = [[CompanyFirstInfoViewController alloc] init];
        IDSVC.isRegisterPush = YES;
        IDSVC.hidesBottomBarWhenPushed = YES;
        [navigationController pushViewController:IDSVC animated:NO];
    } else if ([data[@"user_guide"] isEqualToString:@"company_info"]) { // 填写企业信息
        [SharedApp showViewController:TabBarTypeOfSignin];
        
        RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        CompanySecondInfoViewController *IDSVC = [[CompanySecondInfoViewController alloc] init];
        IDSVC.isRegisterPush = YES;
        IDSVC.hidesBottomBarWhenPushed = YES;
        [navigationController pushViewController:IDSVC animated:NO];
    } else if ([data[@"user_guide"] isEqualToString:@"company_audit"]) { // 企业未认证
        SVPHUDShow;
        [DataToolsControl getMyBaseInfoForCompany:^(BOOL requestFlag) {
            SVPHUDDismiss;
            [SharedApp showViewController:TabBarTypeOfCompany];
            UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
            tabBarController.selectedIndex = tabBarController.viewControllers.count-1;
            RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
            
            CompanyInfoViewController *CIVC = [[CompanyInfoViewController alloc] init];
            CIVC.hidesBottomBarWhenPushed = YES;
            [navigationController pushViewController:CIVC animated:YES];
        }];
    } else if (([data[@"user_guide"] isEqualToString:@"resume_create"])) { // 创建简历页
        [SharedApp showViewController:TabBarTypeOfSignin];
        
        RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        PersonalFirstInfoViewController *PMRVC = [[PersonalFirstInfoViewController alloc] init];
        PMRVC.isRegisterPush = YES;
        PMRVC.hidesBottomBarWhenPushed = YES;
        [navigationController pushViewController:PMRVC animated:NO];
    } else if ([data[@"user_guide"] isEqualToString:@"resume_edu"]) { // 完善简历中教育经历
        if (data[@"is_graduate"] && ([data[@"is_graduate"] integerValue] == 0)) {
            [DataToolsControl sharedManager].idType = IDTypeOfWorker;
        } else {
            [DataToolsControl sharedManager].idType = IDTypeOfFreshGraduate;
        }
        
        [SharedApp showViewController:TabBarTypeOfSignin];
        
        RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        PersonalEducationInfoViewController *PMRVC = [[PersonalEducationInfoViewController alloc] init];
        PMRVC.isRegisterPush = YES;
        PMRVC.hidesBottomBarWhenPushed = YES;
        [navigationController pushViewController:PMRVC animated:NO];
    } else if ([data[@"user_guide"] isEqualToString:@"resume_work"]) { // 完善简历中工作经历
        [SharedApp showViewController:TabBarTypeOfSignin];
        
        RootNavigationController *navigationController = (RootNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        
        PersonalWorkExperienceViewController *PMRVC = [[PersonalWorkExperienceViewController alloc] init];
        PMRVC.isRegisterPush = YES;
        PMRVC.hidesBottomBarWhenPushed = YES;
        [navigationController pushViewController:PMRVC animated:NO];
    }
}

@end
